﻿@{
    if (!IsPost) {
        Response.Redirect("~/Products");
    }

    var db = Database.Open("bakery");
    var productId = Request["ProductId"];
    var product = db.QuerySingle("SELECT * FROM Products WHERE ID = @0", productId);

    var orderShipping = Request["orderShipping"];
    var customerEmail = Request["orderEmail"];
    
    var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped) + Request.ApplicationPath;
    var cancelUrl = hostUrl + "Products";
    var returnUrl = hostUrl + "Success";
    
    var supplierAmount = decimal.Round(product.Price * .10m, 2);
      
    var MyStore = new PayPal.AdaptivePayments.Receiver();
    MyStore.amount = product.Price;
    
    // Enter the email of the primary receiver of the money
    MyStore.email = "";
    
    var Suppliers = new List<PayPal.AdaptivePayments.Receiver>();
    var Supplier = new PayPal.AdaptivePayments.Receiver();
    
    // Enter the email of the secondary receiver of the money
    Supplier.email = "";
    Supplier.amount = supplierAmount;
    Suppliers.Add(Supplier);
  
    var response = PayPal.AdaptivePayments.ChainedPay.Execute
                    (MyStore, Suppliers, "", "Test Payment", "127.0.0.1", "MyDevice", cancelUrl, returnUrl);   
  
    response.Redirect();
}
